package xyz.mvfast.util;

import java.util.Date;

/**
 * @author fuzeqiang
 * @projectName easy-import
 * @title: DataConveter
 * @date 2021/5/24 16:20
 */
public class DataConveter {


    /**
     * 数据类型转化
     * @param value
     * @param dataType
     * @param formatter
     * @return
     */
    public static Object conveter(String value, Class dataType, String formatter){
        Object data = null;
        //数据判空
        if (StringUtil.isEmpty(value)){
            return data;
        }
        if (dataType.equals(Integer.class)){
            data = Integer.parseInt(value);
        }else if (dataType.equals(Long.class)){
            data = Long.parseLong(value);
        }else if (dataType.equals(Short.class)){
            data = Short.parseShort(value);
        }else if (dataType.equals(Float.class)){
            data = Float.parseFloat(value);
        }else if (dataType.equals(Double.class)){
            data = Double.parseDouble(value);
        }else if (dataType.equals(Date.class)){
            data = DateTimeUtil.stringToDate(value, formatter);
        }else if (dataType.equals(String.class)){
            data = value;
        }else {
            data = value;
        }
        return data;
    }
}
